```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis实现"附近的人"功能指南 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6B73FF 0%, #000DFF 50%, #0085FF 100%);
        }
        .code-block {
            background: #1E1E1E;
            border-radius: 8px;
            position: relative;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            color: #D4D4D4;
            font-family: 'Courier New', Courier, monospace;
            overflow-x: auto;
        }
        .command-name {
            color: #4EC9B0;
        }
        .command-desc {
            color: #9CDCFE;
        }
        .section-divider {
            width: 80px;
            height: 4px;
            background: linear-gradient(90deg, #6B73FF 0%, #0085FF 100%);
            margin: 2rem auto;
        }
        .feature-card {
            transition: all 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .mermaid-container {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-4">
        <div class="max-w-6xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">Redis实现"附近的人"功能</h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto opacity-90 mb-8">探索如何使用Redis的地理位置功能在现代应用中实现高效的附近用户发现</p>
            <div class="inline-flex space-x-4">
                <a href="#implementation" class="bg-white text-blue-700 px-6 py-3 rounded-md font-medium hover:bg-blue-50 transition duration-300">
                    <i class="fas fa-code mr-2"></i>实现原理
                </a>
                <a href="#springboot" class="bg-blue-900 text-white px-6 py-3 rounded-md font-medium hover:bg-blue-800 transition duration-300">
                    <i class="fas fa-project-diagram mr-2"></i>Spring Boot集成
                </a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-4 py-12">
        <!-- Introduction -->
        <div class="mb-16">
            <p class="text-lg text-gray-700 mb-6">
                "附近的人"功能是现代社交应用中常见的功能，它允许用户查看周围其他用户的位置信息。Redis提供的地理位置(Geospatial)功能是实现这一需求的理想选择，具有高性能、低延迟和易用性等特点。
            </p>
            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded-r-md">
                <p class="text-blue-800 font-medium"><i class="fas fa-lightbulb mr-2 text-blue-600"></i>Redis的地理位置功能基于Geohash算法，将二维的经纬度坐标转换为一维的字符串编码，从而实现高效的地理位置查询。</p>
            </div>
        </div>

        <!-- Redis Implementation -->
        <section id="implementation" class="mb-20">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">Redis实现原理</h2>
            <div class="section-divider"></div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="feature-card bg-white p-6">
                    <div class="text-blue-600 mb-4">
                        <i class="fas fa-database text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">存储位置信息</h3>
                    <p class="text-gray-600">将用户的ID及其经纬度坐标存储在Redis的地理位置数据结构中，使用GEOADD命令完成。</p>
                </div>
                <div class="feature-card bg-white p-6">
                    <div class="text-green-600 mb-4">
                        <i class="fas fa-search-location text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">查询附近用户</h3>
                    <p class="text-gray-600">使用GEORADIUS或GEORADIUSBYMEMBER命令，根据指定中心点和半径查询附近的用户。</p>
                </div>
            </div>

            <!-- Redis Commands -->
            <h3 class="text-2xl font-semibold mb-6 text-gray-800">Redis地理位置相关命令</h3>
            
            <div class="mb-8">
                <h4 class="text-xl font-medium mb-4 text-gray-700">1. GEOADD - 添加位置信息</h4>
                <div class="code-block">
                    <pre><span class="command-name">GEOADD</span> <span class="command-desc">key longitude latitude member [longitude latitude member ...]</span></pre>
                </div>
                <p class="mt-4 text-gray-600">示例：</p>
                <div class="code-block mt-2">
                    <pre>GEOADD user_locations 113.887888 22.583624 toString
GEOADD user_locations 113.868988 22.581956 admin
GEOADD user_locations 113.877324 22.575482 zhang</pre>
                </div>
            </div>

            <div class="mb-8">
                <h4 class="text-xl font-medium mb-4 text-gray-700">2. GEORADIUS - 查询附近用户</h4>
                <div class="code-block">
                    <pre><span class="command-name">GEORADIUS</span> <span class="command-desc">key longitude latitude radius m|km [WITHDIST] [WITHCOORD] [WITHHASH] [COUNT count] [ASC|DESC]</span></pre>
                </div>
                <p class="mt-4 text-gray-600">示例（查询1公里范围内的用户并返回距离）：</p>
                <div class="code-block mt-2">
                    <pre>GEORADIUS user_locations 113.875456 22.578485 1 km WITHDIST ASC</pre>
                </div>
            </div>

            <div class="mb-8">
                <h4 class="text-xl font-medium mb-4 text-gray-700">3. GEOHASH - 获取位置哈希值</h4>
                <div class="code-block">
                    <pre><span class="command-name">GEOHASH</span> <span class="command-desc">key member [member ...]</span></pre>
                </div>
                <p class="mt-4 text-gray-600">示例：</p>
                <div class="code-block mt-2">
                    <pre>GEOHASH user_locations toString admin zhang</pre>
                </div>
            </div>

            <div class="mb-8">
                <h4 class="text-xl font-medium mb-4 text-gray-700">4. GEOPOS - 获取位置坐标</h4>
                <div class="code-block">
                    <pre><span class="command-name">GEOPOS</span> <span class="command-desc">key member [member ...]</span></pre>
                </div>
                <p class="mt-4 text-gray-600">示例：</p>
                <div class="code-block mt-2">
                    <pre>GEOPOS user_locations toString admin zhang</pre>
                </div>
            </div>

            <div class="mb-8">
                <h4 class="text-xl font-medium mb-4 text-gray-700">5. GEODIST - 计算位置距离</h4>
                <div class="code-block">
                    <pre><span class="command-name">GEODIST</span> <span class="command-desc">key member1 member2 [m|km|mi|ft]</span></pre>
                </div>
                <p class="mt-4 text-gray-600">示例（计算两个用户之间的距离，单位：千米）：</p>
                <div class="code-block mt-2">
                    <pre>GEODIST user_locations admin zhang km</pre>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">地理位置查询流程</h2>
            <div class="section-divider"></div>
            
            <div class="mermaid-container">
                <div class="mermaid">
                    graph TD
                        A[用户A请求附近的人] --> B[获取用户A的经纬度]
                        B --> C[使用GEORADIUS查询]
                        C --> D[Redis返回附近用户列表]
                        D --> E[过滤、排序结果]
                        E --> F[返回给用户A]
                </div>
            </div>
        </section>

        <!-- Spring Boot Integration -->
        <section id="springboot" class="mb-20">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">Spring Boot集成实现</h2>
            <div class="section-divider"></div>
            
            <div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
                <div class="bg-gray-800 text-white px-4 py-3 flex items-center">
                    <i class="fas fa-code-branch mr-2"></i>
                    <span class="font-mono">UserLocationService.java</span>
                </div>
                <div class="code-block">
                    <pre>package com.ts.redisgeo.service;

import com.ts.redisgeo.vo.UserLocation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.*;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserLocationService {

    String key = "user_locations";

    @Autowired
    private StringRedisTemplate redisTemplate;

    public void addUserLocation(UserLocation location) {
        redisTemplate.opsForGeo().add(key, 
            new RedisGeoCommands.GeoLocation<>(location.getUserId(), 
            new Point(location.getLongitude(), location.getLatitude())));
    }

    public GeoResults&lt;RedisGeoCommands.GeoLocation&lt;String&gt;&gt; getNearbyUsers(
            UserLocation location, double radius) {
        Distance distance = new Distance(radius, RedisGeoCommands.DistanceUnit.METERS);
        RedisGeoCommands.GeoRadiusCommandArgs args = RedisGeoCommands.GeoRadiusCommandArgs
            .newGeoRadiusArgs()
            .includeDistance()
            .sortAscending()
            .limit(10);
        return redisTemplate.opsForGeo().radius(key, 
            new Circle(new Point(location.getLongitude(), location.getLatitude()), distance), args);
    }
}</pre>
                </div>
            </div>

            <div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
                <div class="bg-gray-800 text-white px-4 py-3 flex items-center">
                    <i class="fas fa-code-branch mr-2"></i>
                    <span class="font-mono">UserLocationController.java</span>
                </div>
                <div class="code-block">
                    <pre>package com.ts.redisgeo.controller;

import com.ts.redisgeo.service.UserLocationService;
import com.ts.redisgeo.vo.UserLocation;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserLocationController {

    @Resource
    private UserLocationService userLocationService;

    @PostMapping("/user/addLocation")
    public void addUserLocation(@RequestBody UserLocation userLocation) {
        userLocationService.addUserLocation(userLocation);
    }

    @PostMapping("/user/nearby")
    public GeoResults&lt;RedisGeoCommands.GeoLocation&lt;String&gt;&gt; getNearbyUsers(
            @RequestParam double longitude,
            @RequestParam double latitude,
            @RequestParam double radius) {
        UserLocation location = new UserLocation(longitude, latitude, null);
        return userLocationService.getNearbyUsers(location, radius);
    }
}</pre>
                </div>
            </div>

            <div class="bg-white rounded-lg shadow-md overflow-hidden">
                <div class="bg-gray-800 text-white px-4 py-3 flex items-center">
                    <i class="fas fa-code-branch mr-2"></i>
                    <span class="font-mono">UserLocation.java</span>
                </div>
                <div class="code-block">
                    <pre>package com.ts.redisgeo.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserLocation {
    private double longitude;
    private double latitude;
    private String userId;
}</pre>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-blue-50 p-8 rounded-xl">
            <h3 class="text-2xl font-semibold mb-4 text-gray-800">关键要点</h3>
            <ul class="list-disc pl-6 space-y-2 text-gray-700">
                <li>Redis的地理位置功能基于有序集合(zset)实现，使用Geohash算法进行位置编码</li>
                <li>GEOADD命令时间复杂度为O(log(N))，N为有序集合中的元素数量</li>
                <li>GEORADIUS命令默认返回未排序的结果，可通过ASC/DESC参数指定排序方式</li>
                <li>Spring Data Redis提供了友好的API来操作Redis的地理位置功能</li>
                <li>在实际应用中，可以考虑对结果进行缓存以提高性能</li>
            </ul>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="max-w-6xl mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold">技术小馆</h3>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="hover:text-blue-300 transition duration-200">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```